import logging
from datetime import timedelta

from redis import StrictRedis


# 设置配置信息
class Config(object):
    # 秘钥
    SECRET_KEY = "fjkdjfkdjfkdjkfjkdjfkdjfkdjfkd"
    DEBUG = True
    SEND_FILE_MAX_AGE_DEFAULT = 24 * 3600 #更改图片缓存时间

    # 1,数据库的配置信息
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:mysql@localhost:3306/info11"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    # 2,redis配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # 3,配置session信息
    SESSION_TYPE = "redis"
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    SESSION_USE_SIGNER = True
    PERMANENT_SESSION_LIFETIME = timedelta(days=2)  # session保存的时间2天

    # 默认的日志级别
    LEVEL = logging.DEBUG


# 开发环境
class DevelopConfig(Config):
    pass


# 生产环境(线上环境)
class ProductConfig(Config):
    DEBUG = False
    LEVEL = logging.ERROR


# 测试环境
class TestingConfig(Config):
    TESTING = True


# 提供一个容器(字典)去管理所有的配置类
config_dict = {
    "develop": DevelopConfig,
    "product": ProductConfig,
    "testing": TestingConfig
}
